﻿using lingopen.Application;
using lingopen.Application.System;
using lingopen.Entity.System;
using lingopen.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace lingopen.Jabil.Server.Areas.SystemManage.Controllers
{
    [Area(AreaNames.SystemManage)]
    [LoginAuthorizeAttribute]
    public class DutyController : WebController
    {
        public ActionResult Index()
        {
            List<SelectOption> departmentList = SelectOption.CreateList(this.CreateService<IDepartmentAppService>().GetSimpleModels());

            this.ViewBag.DepartmentList = departmentList;
            this.ViewBag.DepartmentListString = JsonHelper.Serialize(departmentList);

            return View();
        }

        [HttpGet]
        public ActionResult GetModels(Pagination pagination, string keyword)
        {
            PagedData<Sys_Duty> data = this.CreateService<IDutyAppService>().GetDutyList(pagination,keyword);
            return this.SuccessData(data);
        }

        [HttpPost]
        public ActionResult Add(AddBLEDutyInput input)
        {
            input.CreateUserId = this.CurrentSession.UserId;
            this.CreateService<IEntityAppService>().AddFromDto<Sys_Duty, AddBLEDutyInput>(input);
            return this.AddSuccessMsg();
        }
        [HttpPost]
        public ActionResult Update(UpdateBLEDutyInput input)
        {
            this.CreateService<IEntityAppService>().UpdateFromDto<Sys_Duty, UpdateBLEDutyInput>(input);
            return this.UpdateSuccessMsg();
        }

        [HttpPost]
        public ActionResult Delete(string id)
        {
            this.CreateService<IEntityAppService>().SoftDelete<Sys_Duty>(id, this.CurrentSession.UserId);
            return this.DeleteSuccessMsg();
        }
    }

}